using System;

namespace Toolbox.DnsService.Events
{
    /// <summary>
    /// DNS请求事件参数
    /// 作者：huobing
    /// </summary>
    public class DnsRequestEventArgs : EventArgs
    {
        /// <summary>
        /// 域名
        /// </summary>
        public string Domain { get; }
        
        /// <summary>
        /// 解析的IP地址
        /// </summary>
        public string ResolvedIp { get; }
        
        /// <summary>
        /// 请求来源IP
        /// </summary>
        public string SourceIp { get; }
        
        /// <summary>
        /// 请求时间
        /// </summary>
        public DateTime RequestTime { get; }
        
        /// <summary>
        /// 是否来自缓存
        /// </summary>
        public bool IsCached { get; }
        
        /// <summary>
        /// 远程端点（用于上游查询）
        /// </summary>
        public System.Net.IPEndPoint? RemoteEndPoint { get; }
        
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="domain">域名</param>
        /// <param name="resolvedIp">解析的IP地址</param>
        /// <param name="sourceIp">请求来源IP</param>
        /// <param name="isCached">是否来自缓存</param>
        /// <param name="remoteEndPoint">远程端点</param>
        public DnsRequestEventArgs(string domain, string resolvedIp, string sourceIp, bool isCached = false, System.Net.IPEndPoint? remoteEndPoint = null)
        {
            Domain = domain;
            ResolvedIp = resolvedIp;
            SourceIp = sourceIp;
            IsCached = isCached;
            RemoteEndPoint = remoteEndPoint;
            RequestTime = DateTime.Now;
        }
    }
    
    /// <summary>
    /// DNS服务状态事件参数
    /// 作者：huobing
    /// </summary>
    public class DnsServiceStatusEventArgs : EventArgs
    {
        /// <summary>
        /// 状态消息
        /// </summary>
        public string Message { get; }
        
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool IsSuccess { get; }
        
        /// <summary>
        /// 状态时间
        /// </summary>
        public DateTime StatusTime { get; }
        
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="message">状态消息</param>
        /// <param name="isSuccess">是否成功</param>
        public DnsServiceStatusEventArgs(string message, bool isSuccess)
        {
            Message = message;
            IsSuccess = isSuccess;
            StatusTime = DateTime.Now;
        }
    }
    
    /// <summary>
    /// DNS测试结果事件参数
    /// 作者：huobing
    /// </summary>
    public class DnsTestResultEventArgs : EventArgs
    {
        /// <summary>
        /// DNS服务器地址
        /// </summary>
        public string DnsServer { get; }
        
        /// <summary>
        /// 测试域名
        /// </summary>
        public string Domain { get; }
        
        /// <summary>
        /// 响应时间（毫秒）
        /// </summary>
        public int ResponseTime { get; }
        
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool IsSuccess { get; }
        
        /// <summary>
        /// 错误消息
        /// </summary>
        public string? ErrorMessage { get; }
        
        /// <summary>
        /// 测试时间
        /// </summary>
        public DateTime TestTime { get; }
        
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="dnsServer">DNS服务器地址</param>
        /// <param name="domain">测试域名</param>
        /// <param name="responseTime">响应时间</param>
        /// <param name="isSuccess">是否成功</param>
        /// <param name="errorMessage">错误消息</param>
        public DnsTestResultEventArgs(string dnsServer, string domain, int responseTime, bool isSuccess, string? errorMessage = null)
        {
            DnsServer = dnsServer;
            Domain = domain;
            ResponseTime = responseTime;
            IsSuccess = isSuccess;
            ErrorMessage = errorMessage;
            TestTime = DateTime.Now;
        }
    }
}